<template>
    <view class="subassembly_goods">
        <u-waterfall v-model="flowList" ref="uWaterfall">
            <template v-slot:left="{leftList}">
                <view class="goods_part" v-for="(item, index) in leftList" :key="index" 
                      @click.stop="jump(item,index)">
					<view class="pa goods_label" v-show="item.is_group">拼团</view>
                    <view class="goods_picture" >
                        <image id="img" :src="item.list_pic_url" mode="widthFix"></image>	
                    </view>
                    <view class="goods_text tl">
                        {{item.spu_name}}
                    </view>
                    <view class="goods_num x-bc">
                        <view class="score">
                            {{ item.points }}
                            <span>积分</span>
                        </view>
                        <view class="num">已兑{{item.sale_num}}件</view>
                    </view>
                </view>
            </template>
            <template v-slot:right="{rightList}">
                <view class="goods_part" v-for="(item, index) in rightList" :key="index"
				 @click.stop="jump(item,index)">
                    <view class="pa goods_label" v-show="item.is_group">拼团</view>
                    <view class="goods_picture" >
                        <image id="img" :src="item.list_pic_url" mode="widthFix"></image>	
                    </view>
                    <view class="goods_text tl">
                        {{item.spu_name}}
                    </view>
                    <view class="goods_num x-bc">
                        <view class="score">
                            {{ item.points }}
                            <span>积分</span>
                        </view>
                        <view class="num">已兑{{item.sale_num}}件</view>
                    </view>
                </view>
            </template>
        </u-waterfall>
    </view>
</template>
<script>
	import {
		mapMutations,
		mapActions,
		mapState,
		mapGetters
	} from 'vuex';
	import mixins from '@/common/mixins.js';
export default {
	mixins:[mixins],
    props: {
        goods_data: {
            type: Array,
            default: ()=>[],
        },
    },
    data() {
        return {
            detail_url: '/pages/goods/detail/index',
            flowList: [],
			click: true, // 处理多次点击
		};
    },
	watch:{
		
	},
    onLoad() {
        
    },
    mounted() {
    },
    computed: {
		list() {
			let arr;
			if (this.goods_data.length != 0) {
				arr = this.addRandomData(this.goods_data);
			}
			if (this.goods_data.length == 0) {
				arr = [];
			}
			return arr;
            
		},
	},
    methods: {
		clear() {
			this.$refs.uWaterfall.clear();
			this.$emit('clean')
		},
		// 重新排序数组     原先数组[1,2,3,4,5,6]    排序后[1,3,5,2,4,6]
        newgoods(list) {
            if (list && list.length > 0 && list.length != 2) {
                let total = { 0: [], 1: [], length: 2 };
                list.forEach((item, index) => {
                    total[index % 2].push(item);
                });
                const newList = [].concat(...Array.from(total));                
                return newList;
            }
			if (list.length == 2) {
				return list;
			}
        },
		jump(item, index) {
			// 处理多次点击
			if (!this.click) {
				return;
			}
			this.click = false;
			let obj = {
				"spu_id": item.spu_id,
				"sku_id": item.sku_id,
			}
			this.$store.dispatch('goods/get_saleNum',item.sale_num)
			this.$api('giftinfo',obj).then(res => {
				let arr  = res
				let goods = arr.data;
				this.$store.dispatch('goods/get_goodsInfo',goods);
				this.goods = this.Info
				this.$emit('getId',item);
				this.click = true;
				this.$Router.push({
					path: this.detail_url,
					params: 'params'
				})
			}).catch(e => {
				this.click = true;
			})
		},
		// 点击选择一栏，弹出对应弹窗
		show_specification() {
			this.$refs.specificationPopup._data.show = true
		},
        addRandomData(list) {
            for(let i = 0; i < list.length; i++) {
                let index = this.$u.random(0, list.length - 1);
                this.flowList.push(this.goods_data[i]);
            };
        }
    }
};
</script>
<style scoped lang='scss'>
@import "./index.scss";
.showBlock:nth-child(2) {
	display: block!important;
}
</style>